package com.aep.ProjetoAnalise;

import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.Toast;

import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: Christian
 * Date: 09/05/13
 * Time: 20:26
 * To change this template use File | Settings | File Templates.
 */
public class TabHostActivity extends TabActivity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tab_host_layout);

        if(!isConnected())
        {
            Toast.makeText(getApplicationContext(), "Não Há Conexão", Toast.LENGTH_SHORT).show();
            this.finish();
        }else{
            TabHost tabHost = getTabHost();
            //Tab de Notícias
            TabSpec noticiasSpec = tabHost.newTabSpec("Notícias");
            noticiasSpec.setIndicator("Notícias",getResources().getDrawable(R.drawable.icon_news48));
            Intent noticiasIntent = new Intent(this, NoticiasActivity.class);
            String nome = this.getIntent().getStringExtra("nome");
            ArrayList<String> fontes = this.getIntent().getStringArrayListExtra("fontes");
            noticiasIntent.putExtra("nome", nome);
            noticiasIntent.putStringArrayListExtra("fontes", fontes);
            noticiasSpec.setContent(noticiasIntent);

            //Tab de Eventos
            TabSpec eventosSpec = tabHost.newTabSpec("Eventos");
            eventosSpec.setIndicator("Eventos", getResources().getDrawable(R.drawable.calendar_icon));
            Intent eventosIntent = new Intent(this, EventosActivity.class);
            eventosSpec.setContent(eventosIntent);

            //Adiciona as Tabs ao TabHost
            tabHost.addTab(noticiasSpec);
            tabHost.addTab(eventosSpec);
        }
    }

    private boolean isConnected(){
        ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        return (cm.getActiveNetworkInfo() != null);
    }
}